<!-- Block user information module HEADER -->
<script type="text/javascript">
	$(document).ready(function(){ldelim}
		/* DIALOG FORM LOGIN */
//		$("#frm-login-dialog").hide();
//		$("#frm-login-dialog").dialog({ldelim}
//				modal: true ,
//				width:400,
//				show:"clip",
//				hide:"clip",
//				autoOpen:false,
//		{rdelim});
//		$('#dialog-login').click(function(){
//			$("#dialog_login_errors").hide();
//			$('#frm-login-dialog').dialog('open');
//			return false;
//		}); 
		$('#dialog-login').fancybox({
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic'
		}); 
		$('#forgot-password').fancybox({
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic'
		}); 
		/* LOGIN FORM SENDING */
		$('#login_form').submit(function() {
			$.ajax({
				
				type: 'POST',
				url: baseDir + 'authentication.php',
				async: false,
				cache: false,
				dataType : "json",
				data: 'SubmitLogin=true&ajax=true&currentI='+encodeURIComponent($('#login_form #currentIndex').val())+'&email='+encodeURIComponent($('#login_form #email').val())+'&passwd='+encodeURIComponent($('#login_form #passwd').val())+'&token=' + static_token ,
				success: function(jsonData)
				{
					var txtThereis = "Có";
					var txtErrors = "lỗi còn tồn tại"; 
					var currentI = ($('#login_form #zcurrentIndex').val());
					if (jsonData.hasError)
					{
//						var errors = '<b>'+txtThereis+' '+jsonData.errors.length+' '+txtErrors+':</b><ol>';
						var errors = '<ol>';
						for(error in jsonData.errors)
							//IE6 bug fix
							if(error != 'indexOf')
								errors += '<li>'+jsonData.errors[error]+'</li>';
						errors += '</ol>';
						$('#dialog_login_errors').html(errors).slideDown('slow');
					}
					else
					{
						window.location.href = currentI;
						$('#login-block').html('<a href="'+jsonData.linkaccount+'" ><span>'+jsonData.fullname+'</span></a>(<a href="'+jsonData.logout+'?mylogout" title="Thoát">Đăng xuất</a>)').slideDown('slow');
//						$('#frm-login-dialog').dialog('close');
						$.fancybox.close();
					}
				},
			});
			return false;
		});
	{rdelim});
</script>
<div id="frm-hidden">
	<div  id="frm-login-dialog" class="frm-login-dialog">
		
		<form action="{$link->getPageLink('authentication.php', true)}" method="post" id="login_form" class="login_form">
			<fieldset>
				<!-- Error return block -->
				<div id="dialog_login_errors" class="error" style="display:none;"></div>
				<!-- END Error return block -->
				<p class="text">
					<span><input type="text" id="email" name="email" value="{if isset($smarty.post.email)}{$smarty.post.email|escape:'htmlall':'UTF-8'|stripslashes}{/if}" class="account_input" /></span>
					<input type="hidden" name="currentIndex" id="zcurrentIndex" value="{$link->getPaginationLink(false, false, false, false, true, false)}" />
				</p>
				<p class="text">
					<span><input type="password" id="passwd" name="passwd" value="{if isset($smarty.post.passwd)}{$smarty.post.passwd|escape:'htmlall':'UTF-8'|stripslashes}{/if}" class="account_input" /></span>
					<span class="span-submit">
						<input type="submit" id="SubmitLogin" name="SubmitLogin" class="button" value="" />
					</span>
				</p>
				<br />
				<p class="lost_password"><a id="forgot-password" href="#frm-forgot-password">{l s='Quên mật khẩu ?'}</a></p>
			</fieldset>
		</form>
	</div>
	<div  id="frm-forgot-password" class="frm-forgot-password" >
		
		<form action="{$link->getPageLink('password.php')}" method="post" id="password-form" class="password-form">
			<fieldset>
				<p class="text">
					<span><input type="text" id="email" name="email" value="{if isset($smarty.post.email)}{$smarty.post.email|escape:'htmlall':'UTF-8'|stripslashes}{/if}" class="account_input" /></span>
					<span class="span-submit">
						<input type="submit" class="button" value="" />
					</span>
				</p>
				<br />
				<br />
				<p class="notification">{l s='Mật khẩu mới sẽ được gửi tới email đăng ký !'}</p>
			</fieldset>
		</form>
	</div>
</div>

<div id="login-block">
	{if $cookie->isLogged()}
		<a href="{$link->getPageLink('my-account.php', true)}"><span>{$cookie->fullname|truncate:10:"...":true}</span></a>
		(<a href="{$link->getPageLink('index.php')}?mylogout" title="{l s='Thoát' mod='blockuserinfo'}">{l s='Đăng xuất' mod='blockuserinfo'}</a>)
	{else}
        <span><a id="dialog-login" href="#frm-login-dialog">{l s='Đăng nhập' mod='blockuserinfo'}</a> | <a href="{$link->getPageLink('authentication.php?register=1', true)}">{l s='Đăng ký' mod='blockuserinfo'}</a></span>
	{/if}
</div>
<!-- /Block user information module HEADER -->